﻿using Pro.DataAccess.Mappings;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Pro.DataAccess.Migrations;

namespace Pro.DataAccess
{
    public class ProDbContext : DbContext
    {
        public ProDbContext()
            : this("DefaultConnection")
        {
        }

        public ProDbContext(string connectionStringName)
            : base(ProEnvironment.ConnectionString(connectionStringName))
        {
            Database.SetInitializer(new CreateDatabaseIfNotExists<ProDbContext>());
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<ProDbContext, Configuration>());
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Configurations.Add(new ContactMapping());

            base.OnModelCreating(modelBuilder);
        }

        public void Commit()
        {
            SaveChanges();
        }
    }
}
